package com.itbour.service.trade.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.trade.ItemComImgInfoDao;
import com.itbour.dto.trade.ItemComImgDto;
import com.itbour.service.trade.ItemComImgInfoService;

/*
 * 通用图片接口实现
 */
public class ItemComImgInfoServiceImpl implements ItemComImgInfoService {

	private ItemComImgInfoDao itemComImgInfoDao;

	@Override
	public void addItemComImgInfo(ItemComImgDto itemComImgDto) {
		Map<String, Object> parm = new HashMap<String, Object>();
		parm.put("type_id", itemComImgDto.getType_id());
		parm.put("thumbs", itemComImgDto.getThumbs());
		parm.put("desc", itemComImgDto.getDesc());
		parm.put("update_by", itemComImgDto.getUpdate_by());
		itemComImgInfoDao.insertItemComImgInfo(parm);
	}

	@Override
	public Page pageListComImgInfo(Integer pageNum, Integer pageSize,
			Map<String, Object> parm) {
		/*
		 * pageNum 第几页 pageSize 一页几条数据 skipNum 起始位置Limit 0,10; totalSize
		 * 总共多少条数据
		 */
		Page page = null;
		int skipNum = JspPage.getStartOfPage(pageNum, pageSize);// 获取起始位置
		int totalSize = itemComImgInfoDao.selectItemsComImgCnt(parm);

		while (totalSize > 0 && totalSize <= skipNum) {
			skipNum = skipNum - pageSize;
			pageNum = pageNum - 1;
		}

		// 分页检索
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipNum);
		List<ItemComImgDto> data = itemComImgInfoDao.selectItemComImgInfo(parm);
		page = new JspPage(skipNum, totalSize, pageSize, data);
		return page;
	}

	public void updItemComImgInfo(ItemComImgDto itemComImgDto){
		Map<String, Object> parm=new HashMap<String, Object>();
		parm.put("id", itemComImgDto.getId());
		parm.put("type_id", itemComImgDto.getType_id());
		parm.put("thumbs", itemComImgDto.getThumbs());
		parm.put("desc", itemComImgDto.getDesc());
		parm.put("update_by", itemComImgDto.getUpdate_by());
		itemComImgInfoDao.updItemComImgInfo(parm);
	}
	

	@Override
	public void applicationComImg(Map<String, Object> parm) {
		itemComImgInfoDao.applicationComImg(parm);
	}
	
	@Override
	public List<ItemComImgDto> selectOneComImgInfo(Map<String, Object> parm) {
		return itemComImgInfoDao.selectOneComImgInfo(parm);
	}
	
	public void delComImgInfo(Map<String, Object> parm){
			itemComImgInfoDao.delComImgInfo(parm);
	}
	
	@Override
	public int countByTypeid(Map<String, Object> parm) {
		return itemComImgInfoDao.countByTypeId(parm);
	}

	public ItemComImgInfoDao getItemComImgInfoDao() {
		return itemComImgInfoDao;
	}

	public void setItemComImgInfoDao(ItemComImgInfoDao itemComImgInfoDao) {
		this.itemComImgInfoDao = itemComImgInfoDao;
	}
}
